package com.taldh.algorithm.listnode;

import com.taldh.algorithm.base.ListNode;

public class ReversePrint {

    public int[] reversePrint(ListNode head) {
        int nums = 0;
        ListNode newhead = new ListNode(-1);
        while (head != null){
            ListNode next = head.next;
            head.next = newhead.next;
            newhead.next = head;
            head = next;
            nums++;
        }
        int[] ans = new int[nums];
        int i = 0;
        while (newhead.next != null) {
            ans[i++]=newhead.next.val;
            newhead.next = newhead.next.next;
        }
        return ans;
    }
}